package book;

import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/26 8:15
 */
public class Test {
    static BookDaoDB dao=new BookDaoDB();
    static Scanner scanner=new Scanner(System.in);
    static Scanner scannerDouble=new Scanner(System.in);
    static Scanner scannerInt =new Scanner(System.in);
    public static void main(String[] args) {
        while (true){
            System.out.println("欢迎");
            System.out.println("1.保存");
            System.out.println("2.查询");
            System.out.println("3.更新");
            System.out.println("4.删除");
            System.out.println("5.退出");
            System.out.println("请选择");
            int choose=scannerInt.nextInt();
            switch (choose){
                case 1:
                    insertUI();
                    break;
                case 2:
                    selectUI();
                    break;
                case 3:
                    updateUI();
                case 4:
                    delectUI();
                case 5:
                    System.exit(0);
            }
        }
    }

    private static void delectUI() {
        dao.delect();
    }

    private static void updateUI() {
        dao.update();
    }

    private static void insertUI(){
        System.out.println("书名");
        String name=scanner.nextLine();
        System.out.println("出版社");
        String press =scanner.nextLine();
        System.out.println("作者");
        String author=scanner.nextLine();
        System.out.println("价格");
        double price=scannerDouble.nextDouble();
        Book book=new Book(name,press,author,price);
        int c=dao.insert(book);
        if (c>0){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    private static void selectUI(){
        dao.select();
    }
}
